package controllers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.DealModel;

import data.DealData;

@SuppressWarnings("serial")
public class DealDemoServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		response.setCharacterEncoding("UTF-8");
		String[] splitted = request.getRequestURI().split("/");
		String id = "";
		if (splitted.length == 3) {
			id = splitted[1];
		} else {			
			request.getRequestDispatcher("/pages/error.jsp").forward(request,
					response);
		}
		DealModel deal = DealData.getDemoById(id);
		if (deal != null && (deal.getStatus()==1||deal.getStatus()==0)) {			
			request.setAttribute("deal", deal);
			request.getRequestDispatcher("/pages/deal_demo.jsp").forward(
					request, response);
		} else {			
			request.getRequestDispatcher("/pages/error.jsp").forward(request,
					response);
		}

	}
}
